package com.ruoyi.web.controller.pcapp;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.app.domain.AppCaseInfo;
import com.ruoyi.app.service.IAppCaseInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 案件信息Controller
 * 
 * @author ruoyi
 * @date 2019-12-13
 */
@Controller
@RequestMapping("/pc/info")
public class PcCaseInfoController extends BaseController
{
    private String prefix = "app/info";

    @Autowired
    private IAppCaseInfoService appCaseInfoService;

    @RequiresPermissions("app:info:view")
    @GetMapping()
    public String info()
    {
        return prefix + "/info";
    }

    /**
     * 查询案件信息列表
     */
    @RequiresPermissions("app:info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AppCaseInfo appCaseInfo)
    {
        startPage();
        List<AppCaseInfo> list = appCaseInfoService.selectAppCaseInfoList(appCaseInfo);
        return getDataTable(list);
    }

    /**
     * 导出案件信息列表
     */
    @RequiresPermissions("app:info:export")
    @Log(title = "案件信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AppCaseInfo appCaseInfo)
    {
        List<AppCaseInfo> list = appCaseInfoService.selectAppCaseInfoList(appCaseInfo);
        ExcelUtil<AppCaseInfo> util = new ExcelUtil<AppCaseInfo>(AppCaseInfo.class);
        return util.exportExcel(list, "info");
    }

    /**
     * 新增案件信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存案件信息
     */
    @RequiresPermissions("app:info:add")
    @Log(title = "案件信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AppCaseInfo appCaseInfo)
    {
        return toAjax(appCaseInfoService.insertAppCaseInfo(appCaseInfo));
    }

    /**
     * 修改案件信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AppCaseInfo appCaseInfo = appCaseInfoService.selectAppCaseInfoById(id);
        mmap.put("appCaseInfo", appCaseInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存案件信息
     */
    @RequiresPermissions("app:info:edit")
    @Log(title = "案件信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AppCaseInfo appCaseInfo)
    {
        return toAjax(appCaseInfoService.updateAppCaseInfo(appCaseInfo));
    }

    /**
     * 删除案件信息
     */
    @RequiresPermissions("app:info:remove")
    @Log(title = "案件信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(appCaseInfoService.deleteAppCaseInfoByIds(ids));
    }
}
